package top.shmly.universal.config.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import top.shmly.universal.base.response.ResponseCode;
import top.shmly.universal.base.response.ResponseResult;
import top.shmly.universal.utils.impl.ResponseJsonUtilsImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: universal
 * @description: Jwt认证入口点
 * @author: Jibny
 * @date 2021-04-26 14:42:27
 */
@Slf4j
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        log.debug("用户未提供Authentication在Header中，表明未登录");
        ResponseJsonUtilsImpl.getInstance().sendMsgWithServletResponse(response, HttpServletResponse.SC_OK, new ResponseResult<>().ok(ResponseCode.CODE_401));
    }
}
